//
//  LLPersonTopView.m
//  UserUse
//
//  Created by Yiwi on 16/10/14.
//  Copyright © 2016年 CJPC. All rights reserved.
//

#import "LLPersonTopView.h"

@interface LLPersonTopView (){
    UIImageView * _iconImageView;
    UILabel * _nameLabel;
    UILabel *_iphoneLabel;
    UILabel *_carNumLabel;
}
@end

@implementation LLPersonTopView


-(void)setupNoLoginVeiw{
    _iconImageView = [UIImageView new];
    _iconImageView.image = [UIImage imageNamed:@"icon"];
    _iconImageView.layer.masksToBounds = YES;
    _iconImageView.layer.cornerRadius = kScaleNum(55)/2;
    [self addSubview:_iconImageView];
    
    _nameLabel = [UILabel new];
    _nameLabel.font = [UIFont systemFontOfSize:18];
    _nameLabel.textColor = kColoeString(@"#333333");
    [self addSubview:_nameLabel];
    
    _iphoneLabel = [UILabel new];
    _iphoneLabel.font = [UIFont systemFontOfSize:16];
    _iphoneLabel.textColor = kColoeString(@"#666666");
    [self addSubview:_iphoneLabel];
    
    _carNumLabel = [UILabel new];
    _carNumLabel.font = [UIFont systemFontOfSize:16];
    _carNumLabel.textColor = kColoeString(@"#666666");
    [self addSubview:_carNumLabel];
    
    UIButton * jumpButton = [UIButton new];
    [jumpButton addTarget:self action:@selector(clickJump) forControlEvents:UIControlEventTouchUpInside];
    [jumpButton setImage:[UIImage imageNamed:@"jumpTo"] forState:UIControlStateNormal];
    [self addSubview:jumpButton];
    
    [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kScaleNum(20));
        make.centerY.equalTo(self.mas_centerY);
        make.width.height.equalTo(@(kScaleNum(55)));
    }];
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(kScaleNum(23/2));
        make.left.equalTo(_iconImageView.mas_right).offset(kScaleNum(10));
    }];
    
    [_iphoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nameLabel.mas_bottom).offset(kScaleNum(3));
        make.left.equalTo(_iconImageView.mas_right).offset(kScaleNum(10));
    }];
    
    [_carNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_iphoneLabel.mas_bottom).offset(kScaleNum(1));
        make.left.equalTo(_iconImageView.mas_right).offset(kScaleNum(10));
    }];
    
    [jumpButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-kScaleNum(15));
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@(kScaleNum(15)));
        make.height.equalTo(@(kScaleNum(30)));
    }];
}

-(void)setupLoginView{
    UIImageView * backImageView = [UIImageView new];
    backImageView.frame = self.frame;
    backImageView.image = [UIImage imageNamed:@"loginBackground"];
    [self addSubview:backImageView];
    
    _iconImageView = [UIImageView new];
    _iconImageView.backgroundColor = [UIColor grayColor];
    _iconImageView.image = [UIImage imageNamed:@"icon"];
    _iconImageView.layer.masksToBounds = YES;
    _iconImageView.layer.cornerRadius = kScaleNum(55)/2;
    [self addSubview:_iconImageView];
    
    
    UIButton * loginButton = [UIButton new];
    [loginButton addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
    [loginButton setImage:[UIImage imageNamed:@"login"] forState:UIControlStateNormal];
    [self addSubview:loginButton];
    
    [backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self);
    }];
    
    [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kScaleNum(20));
        make.centerY.equalTo(self.mas_centerY);
        make.width.height.equalTo(@(kScaleNum(55)));
    }];
    
    [loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_iconImageView.mas_right).offset(kScaleNum(20));
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@(kScaleNum(50)));
        make.height.equalTo(@(kScaleNum(20)));
    }];
    
}


-(void)setupLoginVeiwWithUer:(LLUserModel*)user{
    if (user) {
         _iconImageView.image = [UIImage imageNamed:@"icon"];
        if (![user.UserIconUrl isEqual:[NSNull null]]) {
            if (![user.UserIconUrl isEqualToString:@""]) {
                [_iconImageView sd_setImageWithURL:[NSURL URLWithString:user.UserIconUrl]];
            }
        }
        
        _nameLabel.text = user.UserName;
        _iphoneLabel.text = user.UserTelephone;
        _carNumLabel.text = user.usernumber;
    }

}


-(void)login{
    [self.delegate login];
}

-(void)clickJump{
    [self.delegate jumpdetail];
}

@end
